// packageD/wxliveDetail/wxliveDetail.js
var app = getApp();
const skinBehavior = require('../../utils/themeSkin/skinBehavior');
Page({
  behaviors: [skinBehavior],
  /**
   * 页面的初始数据
   */
  data: {
    liveInfo: {},
    posterShow: false, // 海报
    rid: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.scene){
      let scene = decodeURIComponent(options.scene);
      // 扫码进入
      if (scene) {
        let info_arr = [];
        info_arr = scene.split(',');
        for (let i = 0; i < info_arr.length; i++) {
          let chil_arr = [];
          chil_arr = info_arr[i].split('=');
          if (chil_arr[0] == 'mid') {
            app._setMid(chil_arr[1]);
          }
          if (chil_arr[0] == 'roomid') {
            this.roomid = chil_arr[1];
          }
        }
      }
    } 
    if(options.roomid) this.roomid = options.roomid;
    
    this.getiPnoneBottom();
    this.getLive();
  },

  getLive() {
    let urlStr = app.getNetAddresss("plugin.appletslive.frontend.controllers.live.get-detail");
    app._postNetWork({
      url: urlStr,
      data: {roomid: this.roomid},
      success: (resdata)=> {
        let res = resdata.data;
        if(res.result == 0) return app.tips(res.msg);
        this.setData({liveInfo: res.data,rid: res.data.has_one_room.roomid})
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  gotoLive(){
    if(this.data.liveInfo.has_one_room.live_status == 101 || this.data.liveInfo.has_one_room.close_replay ==  0) {
      let roomId = this.roomid;
      let value = wx.getStorageSync("yz_uid");
      let customParams = { mid: value };
      wx.navigateTo({
        url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${encodeURIComponent(
          JSON.stringify(customParams)
        )}`,
      });
    }
  },
  sharePosterPop(){
    this.setData({
      posterShow: true,
    });
  },
  getiPnoneBottom() {
    try {
      var value = wx.getStorageSync("iPhoneBottom");
      if (value) {
        this.setData({
          iPnoneBottomBol: true,
        });
        // Do something with return value
      }
    } catch (e) {
      // Do something when catch error
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      path: `/packageD/wxliveDetail/wxliveDetail?roomid=${this.roomid}`,
    }
  }
})
